home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / recovserverinfo / recovserverinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-13  |  8.0 KB  |  251 lines

  1. #include    "sprite.h"
  2. #include    "status.h"
  3. #include    "stdio.h"
  4. #include    "sysStats.h"
  5. #include    "spriteTime.h"
  6. #include    "host.h"
  7. #include    "option.h"
  8.  
  9. int        numStats = 100;    /* A good number to try first. */
  10.  
  11. /*
  12.  * For per-client statistics about recovery on the server.  This amounts to
  13.  * a per-host list, in array form, where the first element in each list is the
  14.  * Sys_RecovPerHostFirstInfo, and all the following items are time-stamps,
  15.  * but they are defined as a union since both types of elements must be the
  16.  * same size when copied out to the user (here).  Each host has a
  17.  * Sys_RecovPerHostFirstInfo, followed by (numTries - 1) time-stamps.
  18.  */
  19. typedef    struct    Sys_RecovPerHostInfo {
  20.     int        spriteID;    /* Sprite ID of client. */
  21.     Time    start;        /* First recovery attempt. */
  22.     Time    finished;    /* First recovery attempt finished. */
  23.     int        numTries;    /* Number of recovery attempts. */
  24.     int        numHandles;    /* Number of reopens requested. */
  25.     int        numSuccessful;    /* Handles successfully recovered. */
  26. } Sys_RecovPerHostInfo;
  27.  
  28. /*
  29.  * Option declarations.
  30.  */
  31. Boolean        duration = FALSE;
  32. Boolean        noHandles = FALSE;
  33. Boolean        success = FALSE;
  34. Option        optionArray[] = {
  35.     {OPT_TRUE, "noHandles", (char *) &noHandles,
  36.             "Don't include handle reopen counts."},
  37.     {OPT_TRUE, "success", (char *) &success,
  38.             "Show count of successful reopens."},
  39.     {OPT_TRUE, "duration", (char *) &duration,
  40.             "Only show duration of recovery per host."}
  41. };
  42.  
  43. int        numOptions = sizeof (optionArray) / sizeof (Option);
  44.  
  45. main(argc, argv)
  46.     int        argc;
  47.     char    *argv[];
  48. {
  49.     ReturnStatus        status;
  50.     int                bufSize;
  51.     Sys_RecovPerHostInfo    *infoPtr;
  52.     Sys_RecovPerHostInfo    *stats;
  53.     Sys_RecovPerHostInfo    *lastInfoPtr;
  54.     int                i;
  55.     char            firstTimeBuf[26];
  56.     char            finishedTimeBuf[26];
  57.     int                myID;
  58.     Host_Entry            *hostInfoPtr;
  59.     int                numClients = 0;
  60.     int                avgNumTries = 0;
  61.     int                lowTime = 0;
  62.     int                highTime = 0;
  63.     struct            tm    *tp;
  64.     int                numTries;
  65.     int                totalReopenRequests = 0;
  66.     int                totalHandlesReallyReopened = 0;
  67.     int                totalSuccessfulRequests = 0;
  68.     int                totalSuccessfulReallyReopened = 0;
  69.     
  70.     /*
  71.      * Should I wait for 5 minutes, till recovery is probably done, then try
  72.      * to dump
  73.      * recovery statistics and then clear them?  If recovery is still going
  74.      * on, we'll get a failure status and loop around again.
  75.      */
  76.     
  77.     /*
  78.      * Parse arguments.
  79.      */
  80.     Opt_Parse(argc, argv, optionArray, numOptions, 0);
  81.     if (success && noHandles) {
  82.     printf("Options 'success' and 'noHandles' are contradictory.\n");
  83.     exit(1);
  84.     }
  85.  
  86.     bufSize = numStats * sizeof (Sys_RecovPerHostInfo);
  87.     stats = (Sys_RecovPerHostInfo *) malloc(bufSize);
  88.     status = Sys_Stats(SYS_RECOV_CLIENT_INFO, &bufSize, stats);
  89.  
  90.     /*
  91.      * Did we need more space?
  92.      */
  93.     while (status == SUCCESS && (bufSize >
  94.         numStats * sizeof (Sys_RecovPerHostInfo))) {
  95.     numStats = bufSize / sizeof (Sys_RecovPerHostInfo);
  96.  
  97.     if (stats != (Sys_RecovPerHostInfo *) NULL) {
  98.         free(stats);
  99.     }
  100.     stats = (Sys_RecovPerHostInfo *) malloc(bufSize);
  101.     status = Sys_Stats(SYS_RECOV_CLIENT_INFO, &bufSize, stats);
  102.     }
  103.  
  104.     if (status != SUCCESS) {
  105.     printf("Stat call failed, status = 0x%x\n", status);
  106.     exit(1);
  107.     }
  108.     system("echo Recovery info for server `hostname` `date`");
  109.     printf("\n");
  110.     if (noHandles) {
  111.     printf("Host\t\tNumTries\tStarting\t\tFinished\n");
  112.     } else if (success) {
  113.     printf("Host\t\tNumTries\tStarting\t\tFinished\tHandles  Successful\n");
  114.     } else {
  115.     printf("Host\t\tNumTries\tStarting\t\tFinished\tHandles\n");
  116.     }
  117.     numStats = bufSize / sizeof (Sys_RecovPerHostInfo);
  118.     infoPtr = stats;
  119.     for (i = 0; i < numStats; i++) {
  120.     char    *name;
  121.     int    j;
  122.  
  123.     if (infoPtr->numTries == 0) {
  124.         infoPtr++;
  125.         continue;
  126.     }
  127.     numClients++;
  128.     avgNumTries += infoPtr->numTries;    /* divided out later */
  129.     lastInfoPtr = &stats[i + infoPtr->numTries - 1];
  130.     totalReopenRequests += lastInfoPtr->numHandles;
  131.     totalSuccessfulRequests += lastInfoPtr->numSuccessful;
  132.     totalHandlesReallyReopened += lastInfoPtr->numHandles;
  133.     totalSuccessfulReallyReopened += lastInfoPtr->numSuccessful;
  134.     if (lowTime == 0) {
  135.         lowTime = infoPtr->start.seconds;
  136.     } else if (infoPtr->start.seconds < lowTime) {
  137.         lowTime = infoPtr->start.seconds;
  138.     }
  139.     if (lastInfoPtr->finished.seconds > highTime) {
  140.         highTime = lastInfoPtr->finished.seconds;
  141.     }
  142.     hostInfoPtr = Host_ByID(infoPtr->spriteID);
  143.     Host_End();
  144.     if (hostInfoPtr == NULL) {
  145.         name = "unknown";
  146.     } else if (hostInfoPtr->aliases != NULL &&
  147.         hostInfoPtr->aliases[0] != NULL) {
  148.         name = hostInfoPtr->aliases[0];
  149.     } else {
  150.         name = hostInfoPtr->name;
  151.     }
  152.     tp = (struct tm *) localtime(
  153.         (time_t *) &(infoPtr->start.seconds));
  154.     strcpy(firstTimeBuf, asctime(tp));
  155.     tp = (struct tm *) localtime(
  156.         (time_t *) &(lastInfoPtr->finished.seconds));
  157.     strcpy(finishedTimeBuf, asctime(tp));
  158.     /* get rid of newline */
  159.     firstTimeBuf[24] = '\0';
  160.     finishedTimeBuf[24] = '\0';
  161.     if (noHandles) {
  162.         if (strlen(name) >= 8) {
  163.         printf("%s\t%d\t%s\t%s\n", name,
  164.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf);
  165.         } else {
  166.         printf("%s\t\t%d\t%s\t%s\n", name,
  167.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf);
  168.         }
  169.     } else if (success) {
  170.         if (strlen(name) >= 8) {
  171.         printf("%s\t%d\t%s  %s  %d   %d\n", name,
  172.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
  173.             lastInfoPtr->numHandles,
  174.             lastInfoPtr->numSuccessful);
  175.         } else {
  176.         printf("%s\t\t%d\t%s  %s  %d   %d\n", name,
  177.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
  178.             lastInfoPtr->numHandles,
  179.             lastInfoPtr->numSuccessful);
  180.         }
  181.     } else {
  182.         if (strlen(name) >= 8) {
  183.         printf("%s\t%d\t%s  %s  %d\n", name,
  184.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
  185.             lastInfoPtr->numHandles);
  186.         } else {
  187.         printf("%s\t\t%d\t%s  %s  %d\n", name,
  188.             infoPtr->numTries, firstTimeBuf, finishedTimeBuf,
  189.             lastInfoPtr->numHandles);
  190.         }
  191.     }
  192.     if (duration || infoPtr->numTries <= 1) {
  193.         infoPtr++;
  194.         continue;
  195.     }
  196.     numTries = infoPtr->numTries;
  197.     /*
  198.      * Process an additional time-stamp for each numTries over 1.
  199.      */
  200.     for (j = 0; j < numTries; j++) {
  201.         tp = (struct tm *) localtime((time_t *)
  202.             &(infoPtr->start.seconds));
  203.         strcpy(firstTimeBuf, asctime(tp));
  204.         tp = (struct tm *) localtime((time_t *)
  205.             &(infoPtr->finished.seconds));
  206.         strcpy(finishedTimeBuf, asctime(tp));
  207.         if (j < numTries - 1) {    /* last one already included */
  208.         totalReopenRequests += infoPtr->numHandles;
  209.         totalSuccessfulRequests += infoPtr->numSuccessful;
  210.         }
  211.         if (noHandles) {
  212.         /* Remove newline from firstTime */
  213.         firstTimeBuf[24] = '\0';
  214.         printf("\t\t\t%s %s", firstTimeBuf, finishedTimeBuf);
  215.         } else if (success) {
  216.         /* Remove newlines */
  217.         firstTimeBuf[24] = '\0';
  218.         finishedTimeBuf[24] = '\0';
  219.         printf("\t\t\t%s %s  %d  %d\n", firstTimeBuf, finishedTimeBuf,
  220.             infoPtr->numHandles, infoPtr->numSuccessful);
  221.         } else {
  222.         /* Remove newlines */
  223.         firstTimeBuf[24] = '\0';
  224.         finishedTimeBuf[24] = '\0';
  225.         printf("\t\t\t%s  %s  %d\n", firstTimeBuf, finishedTimeBuf,
  226.             infoPtr->numHandles);
  227.         }
  228.         infoPtr++;
  229.     }
  230.     i += (numTries - 1);
  231.     }
  232.     highTime = highTime - lowTime;
  233.     Time_ToAscii(highTime, TRUE, firstTimeBuf);
  234.     if (noHandles) {
  235.     printf(
  236.         "\nNum Clients: %d, Avg Num Tries: %d, Total Time: %s hr:min:sec\n",
  237.         numClients, numClients == 0 ? 0 : (avgNumTries / numClients), firstTimeBuf);
  238.     } else if (success)  {
  239.     printf(
  240.         "\nNum Clients: %d, Avg Num Tries: %d\nTotal Reopen Requests: %d, Total Handles Really Reopened: %d\nTotal Successful Requests: %d, Total Successful Really Reopened: %d\nTotal Time: %s hr:min:sec\n",
  241.         numClients, numClients == 0 ? 0 : (avgNumTries / numClients), totalReopenRequests, totalHandlesReallyReopened, totalSuccessfulRequests, totalSuccessfulReallyReopened,
  242.         firstTimeBuf);
  243.     } else {
  244.     printf(
  245.         "\nNum Clients: %d, Avg Num Tries: %d\nTotal Reopen Requests: %d, Total Handles Really Reopened: %d\nTotal Time: %s hr:min:sec\n",
  246.         numClients, numClients == 0 ? 0 : (avgNumTries / numClients), totalReopenRequests, totalHandlesReallyReopened, firstTimeBuf);
  247.     }
  248.     
  249.     exit(0);
  250. }
  251.